package com.ibiaoke.boss.controller;

import com.ibiaoke.common.base.Page;
import com.ibiaoke.common.response.Res;
import com.ibiaoke.system.entity.Shop;
import com.ibiaoke.system.service.ShopService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * Created by j on 2017/6/20.
 */
@Controller
@RequestMapping("/shop")
public class BossShopController {

    @Autowired
    private ShopService shopService;


    /**
     * 保存店铺信息
     * @param shop
     * @return Res
     */
    @ResponseBody
    @RequestMapping("/saveShop")
    public Res saveShop(Shop shop) {
        shopService.saveShop(shop);
        return Res.create();
    }


    /**
     *更改店铺信息
     * @param shop
     * @return  Res
     */
    @RequestMapping("/updateShop")
    @ResponseBody
    public Res updateShop(Shop shop) {
        shopService.updateShop(shop);
        return Res.create();
    }

    /**
     * 获取店铺详细信息
     * @param  shopId
     * @return shop
     */
    @RequestMapping("/getShopByShopId")
    @ResponseBody
   public Res getShopByShopId(Integer shopId) {
        Shop shop =  shopService.getShop(shopId);
        return Res.create().addResponse("shop", shop);
   }


    /**
     * 获取店铺的列表
     * @return  Res
     */
   @RequestMapping("/listShop")
   @ResponseBody
   public Res listShop() {
       List<Shop> list = shopService.listShop();
       return Res.create().addResponse("shopList", list);
   }

    /**
     * 修改店铺状态为删除状态
     * @param shopId
     * @return  res
     */
    @RequestMapping("/deleteByShopId")
    @ResponseBody
    public Res deleteByShopId(Integer shopId) {
        int deleteResult = shopService.deleteShop(shopId);
        return Res.create().addResponse("deleteResult", deleteResult);
    }
    /**
     * 关联店铺
     * @param shop
     * @return
     */
    @RequestMapping("/relevanceShop")
    @ResponseBody
    public Res relevanceShop(Shop shop) {
        shopService.relevanceShop(shop);
        return Res.create();
    }

}
